<?php

class M_pengurus extends CI_Model{
	
	//var $template = 'admin/admin_template';
    var $path = 'image/gambar_kampus/';

	function __construct(){
		parent::__construct();
	}
	
	function create($id,$nama, $email,$gambar){
		$data = array(
		'id_pngrs' =>$id,
		'nama'=> $nama,
		'email' => $email,
		'foto' => $gambar
		);
	
		$this->db->insert('pengurus', $data);
		if ($this->db->affected_rows() == 1) {
			return TRUE;
		}
		return FALSE;
	}
	
	function getTable($perPage = 0, $offset = 0) {
        $this->db->select('*');
		$this->db->order_by('id_pngrs', 'DESC');
        $this->db->limit($perPage, $offset);
        $query = $this->db->get('pengurus');
		
        
            return $query->result_array();
        
    }
	
	function getAllData(){
		$this->db->select('*');
		$this->db->order_by('id_pngrs', 'DESC');
        $query = $this->db->get('pengurus');
		
        if ($query->num_rows() > 0) {
            return $query->result_array();
        }
	}
	
	function getDataById($id){
		$this->db->select('*');
		$this->db->where('id_pngrs', $id);
		$query = $this->db->get('pengurus');
		
		if($query->num_rows() == 1){
			return $query->result_array();
		}
	}
	
	function update($id,$nama, $email,$gambar){
		$data = array(
		'id_pngrs' =>$id,
		'nama'=> $nama,
		'email' => $email,
		'foto' => $gambar
		);
		$this->db->where('id_pngrs', $id);
		$this->db->update('pengurus', $data);
		
		if ($this->db->affected_rows() == 1) {

            return TRUE;
        }
        return FALSE;
	}
	
	function delete($id){
		$this->db->where('id_pngrs', $id);
		$this->db->delete('pengurus');
		if ($this->db->affected_rows() == 1) {

            return TRUE;
        }
        return FALSE;
	}
	
	function getAllCategories(){
		$this->db->select('*');
		$query = $this->db->get('kategori');
		if($query->num_rows() > 0){
			return $query->result_array();
		}
		return FALSE;
	}
	
	function search($key){
		$this->db->select('*');
		$this->db->like('nama', $key);
		$this->db->order_by('id_pngrs', 'DESC');
		$query = $this->db->get ('pengurus');
		return $query->result_array();
	}

}